const { Sequelize, DataTypes } = require("sequelize");
const sequelize = require('.')
const Visiting = sequelize.define(
  "ServiceVisiting",
  {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    city: {
      type: DataTypes.STRING,
      defaultValue: null,
    },
    showroom: {
      type: DataTypes.STRING,
      defaultValue: null,
    },
    visitTime: {
      type: DataTypes.STRING,
      defaultValue: null,
    },
    intercepter: {
      type: DataTypes.NUMBER,
      defaultValue: 0,
    },
    language: {
      type: DataTypes.INTEGER,
      defaultValue: null,
    },
    version: {
      type: DataTypes.INTEGER,
      defaultValue: null,
    },
    photo: {
      type: DataTypes.INTEGER,
      defaultValue: null,
    },
    remark: {
      type: DataTypes.TEXT,
      defaultValue: null,
    }
  },
  {
    timestamps: false,
  }
);

async function deleteAll() {
  await Visiting.destroy({
    where: {},
    truncate: true,
  });
}

(async () => {
  await Visiting.sync({alter: false}); // Creates the table if it doesn't exist
})();

module.exports = Visiting